package com.whq.thrift.api.web.base.serviceconf.db;

import org.apache.ibatis.jdbc.SqlBuilder;

import com.whq.common.StringUtil;

public class UrlMappingInfoSqlProvider {

	public String updateSql(UrlMappingInfo urlMappingInfo) {
		SqlBuilder.BEGIN();
		SqlBuilder.UPDATE("t_url_mapping");

		if (StringUtil.isNotBlank(urlMappingInfo.getMapParamMethod())) {
			SqlBuilder.SET("map_param_method = #{mapParamMethod}");
		}

		if (urlMappingInfo.getCreateTime() != null) {
			SqlBuilder.SET("create_time = #{createTime}");
		}

		if (urlMappingInfo.getUpdateTime() != null) {
			SqlBuilder.SET("update_time = #{updateTime}");
		}

		SqlBuilder.WHERE("url=#{url}");
		return SqlBuilder.SQL();
	}

	public String getSelectUrlMappingInfoSql(String url) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("*");
		SqlBuilder.FROM("t_url_mapping");

		if (StringUtil.isNotBlank(url)) {
			SqlBuilder.WHERE("url like #{url}");
		}

		return SqlBuilder.SQL() + " limit #{beginIndex}, #{maxCount} ";
	}

	public String getSelectCountSql(String url) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("count(*)");
		SqlBuilder.FROM("t_url_mapping");

		if (StringUtil.isNotBlank(url)) {
			SqlBuilder.WHERE("url like #{url}");
		}

		return SqlBuilder.SQL();
	}

	public String findAllUrlMappingInfo() {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("*");
		SqlBuilder.FROM("t_url_mapping");

		return SqlBuilder.SQL();
	}

}
